
<!-- saved from url=(0067)http://www.5imoban.net/view/js/render-html-to-pdf-master/demo5.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>
      html2canvas example
    </title>
      
    <style type="text/css">
    </style>
  <style type="text/css" abt="234"></style></head>
  <body rlt="1" style="">
      <article>
        <img src="./javascript/1.jpg">

        <button id="renderPdf">下载pdf</button>
        <h2>Stone Giant</h2>
      </article>
    <script type="text/javascript" src="./javascript/html2canvas.js"></script>
    <script type="text/javascript" src="./javascript/jsPdf.debug.js"></script>
    <script type="text/javascript">

      var downPdf = document.getElementById("renderPdf");

      downPdf.onclick = function() {
          html2canvas(document.body, {
              onrendered:function(canvas) {

                  //返回图片URL，参数：图片格式和清晰度(0-1)
                  var pageData = canvas.toDataURL('image/jpeg', 1.0);

                  //方向默认竖直，尺寸ponits，格式a4【595.28,841.89]
                  var pdf = new jsPDF('p', 'pt', 'a4');

                  //需要dataUrl格式
                  pdf.addImage(pageData, 'JPEG', 0, 0, 595.28, 592.28/canvas.width * canvas.height );

                  pdf.save('content.pdf');

              }
          })
      }
    </script>
  
</body>
</html>